home *** CD-ROM | disk | FTP | other *** search
/ Quick PC 61 / Quick PC 61.iso / I386 / WMS.CAB / wmsError.inc < prev    next >
Encoding:
Text File  |  2003-02-21  |  9.5 KB  |  260 lines

  1. <%
  2. '+-------------------------------------------------------------------------
  3. '
  4. '  Microsoft Windows Media
  5. '  Copyright (C) Microsoft Corporation. All rights reserved.
  6. '
  7. '  File:       Error.asp
  8. '
  9. '  Contents:    common error-handling utilities
  10. '
  11. '--------------------------------------------------------------------------
  12.  
  13. '/////////////////////////////////////////////////////////////////////////////////////
  14. ' Debugging tool- display a javascript popup with s specified string
  15. '/////////////////////////////////////////////////////////////////////////////////////
  16. sub DebugDialog( strDebugInfo )
  17.     Dim strOutputString
  18.     if( "\" = mid( strDebugInfo, Len( strDebugInfo ), 1 ) ) then
  19.         strDebugInfo = strDebugInfo & "\"
  20.     end if
  21.     strDebugInfo = Server.HTMLEncode( strDebugInfo )
  22.     strOutputString = "<script language=javascript> alert" & chr(40) & chr(34) & Server.HTMLEncode( CStr( strDebugInfo ) ) & chr(34) & chr(41) & ";</script>"
  23.     Response.Write ( chr(13) & strOutputString & chr(13 ) )
  24. End Sub
  25.  
  26. '/////////////////////////////////////////////////////////////////////////////////////
  27. ' Debugging tool- display each query string name and arg in a simple table
  28. '/////////////////////////////////////////////////////////////////////////////////////
  29. sub DumpQueryString()
  30.     exit sub ' remove this line if you wish to make use of this subroutine
  31.     Dim objQSItem
  32.     on error resume next
  33.     %>
  34.     <div>
  35.     <table valign="top" cellspacing="1" cellpadding="1" bgcolor="silver" border="1">
  36.         <th colspan=2>
  37.             <b>QueryString: <%= Request.QueryString.count %></b>
  38.         </th><%
  39.     
  40.     for each objQSItem in Request.QueryString %>
  41.         <tr>
  42.             <td> <%= Server.HTMLEncode( objQSItem ) %> </td>
  43.             <td><%= Server.HTMLEncode( Request.QueryString( objQSItem ) ) %> </td>
  44.         </tr><%
  45.     next %>
  46.     </table>
  47.     </div>
  48. <%
  49.     objQSItem = nothing
  50. End Sub
  51.  
  52. '/////////////////////////////////////////////////////////////////////////////////////
  53. ' Debugging tool- display each posted form's name and arg in a simple table
  54. '/////////////////////////////////////////////////////////////////////////////////////
  55. sub DumpFormPosting()
  56.     exit sub ' remove this line if you wish to make use of this subroutine
  57.     Dim objFormItem
  58.     on error resume next
  59.     %>
  60.     <div>
  61.     <table valign="top" cellspacing="1" cellpadding="1" bgcolor="silver" border="1">
  62.         <th colspan="2">
  63.             <b>Form Posting  Element count: <%= Request.Form.count %></b>
  64.         </th><%
  65.     for each objFormItem in Request.Form %>
  66.         <tr>
  67.             <td> <%= Server.HTMLEncode( objFormItem ) %> </td>
  68.             <td> <%= Server.HTMLEncode( Request.Form( objFormItem ) ) %> </td>
  69.         </tr><%
  70.     next %>
  71.     </table>
  72.     </div>
  73. <%
  74.     objFormItem = nothing
  75. End Sub
  76.  
  77. '/////////////////////////////////////////////////////////////////////////////////////
  78. ' Debugging tool- dump IIS server variables in a simple table
  79. '/////////////////////////////////////////////////////////////////////////////////////
  80. sub DumpServerVariables()
  81.     exit sub ' remove this line if you wish to make use of this subroutine
  82.     dwNumVars = Request.ServerVariables.Count
  83.     
  84.     Response.Write( "<br>Number of server variables: " & dwNumVars )
  85.     for i = 1 to dwNumVars
  86.         Response.Write( "<br>" & Server.HTMLEncode( Request.ServerVariables.Key( i ) ) & " : " & Server.HTMLEncode( Request.ServerVariables.Item( i ) ) )
  87.     next
  88. End Sub
  89.  
  90. '/////////////////////////////////////////////////////////////////////////////////////
  91. ' Initialize the error handler for the current page
  92. '/////////////////////////////////////////////////////////////////////////////////////
  93. sub BeginErrorHandling()
  94.     if 0 = Session( "PageReloadedToDisplayError" ) then
  95.         Session( "ErrorNumber" ) = 0
  96.         Session( "ErrorCulprit" ) = ""
  97.         Session( "ErrorDescription" ) = ""
  98.         Err.Clear
  99.         ClearError
  100.     end if
  101. End Sub
  102.  
  103.  
  104. '/////////////////////////////////////////////////////////////////////////////////////
  105. '
  106. ' Called at the bottom of a page implementing error handling.  Determines if we need
  107. '  to re-load the page to display error messages or just clear the error state vars.
  108. '
  109. sub EndErrorHandling( WhichASPFile )
  110.  
  111.     if( 0 = Session( "ErrorNumber" ) ) then
  112.         ClearError
  113.     elseif ( 0 <> Session( "PageReloadedToDisplayError" ) ) then
  114.         Session( "PageReloadedToDisplayError" ) = 0
  115.         ClearError
  116.     else
  117.         Session( "PageReloadedToDisplayError" ) = 1
  118.         Response.Redirect( WhichASPFile & "?" & RemoveDangerousCharacters( Request.QueryString ) )
  119.     end if
  120.     
  121. End Sub
  122.  
  123.  
  124. '/////////////////////////////////////////////////////////////////////////////////////
  125. '
  126. ' Returns a bool indicating if an error was detected.  Primes some state variables
  127. '  so that we can call AlertUserWithPopupErrorDialog and OnErrorGoBack later on the page
  128. '
  129. function ErrorDetected( strCulprit )
  130.     dim bErrorDetected
  131.     dim strWMSDescription
  132.     dim dwSavedErrorNum
  133.     dim strSavedErrorDescription
  134.     
  135.     bErrorDetected = FALSE
  136.     
  137.     if 0 <> Err.number  then
  138.         if( 0 = Session( "ErrorNumber" ) ) then
  139.             bErrorDetected = TRUE
  140.             
  141.             if( -1 = Err.Number ) then
  142.             
  143.                 Session( "ErrorDescription" ) = Err.Description
  144.                 Session( "ErrorNumber" ) = Err.Number
  145.                 Session( "ErrorCulprit" ) = strCulprit
  146.  
  147.             else
  148.  
  149.                 dwSavedErrorNum = Err.Number
  150.                 strSavedErrorDescription = Err.Description
  151.                 
  152.                 on error resume next
  153.                 err.number = dwSavedErrorNum
  154.                 err.description = strSavedErrorDescription
  155.                 
  156.                 strWMSDescription = s_WMSAdmin.Error( dwSavedErrorNum )
  157.                 if( "" <> strWMSDescription ) then
  158.                     Session( "ErrorDescription" ) = strWMSDescription
  159.                 else
  160.                     if( 450 = dwSavedErrorNum ) then
  161.                         Session( "ErrorDescription" ) = L_UNSPECIFIEDERR_TEXT
  162.                         Session( "ErrorNumber" ) = "?"
  163.                     else
  164.                         Session( "ErrorDescription" ) = strSavedErrorDescription
  165.                     end if
  166.                 end if
  167.                 Session( "ErrorNumber" ) = dwSavedErrorNum
  168.                 Session( "ErrorCulprit" ) = strCulprit
  169.  
  170.             end if
  171.         end if
  172.     end if 
  173.  
  174.     ErrorDetected = bErrorDetected
  175.  
  176. end function
  177.  
  178.  
  179. '/////////////////////////////////////////////////////////////////////////////////////
  180. '
  181. ' Called at the bottom of a page when it reloads.  Requires JavaScript on the browser
  182. '
  183. sub AlertUserWithPopupErrorDialog()
  184.     if 0 <> Session( "ErrorNumber" ) then
  185.         Dim strError, strError2, strErrorWithoutLF, dwOffsetToQuoteChar
  186.         
  187.         strError = Session( "ErrorDescription" )
  188.  
  189.         ' Remove illegal chars and work around quote chars
  190.         dwOffsetToQuoteChar = InStr( 1, strError, chr(34), vbTextCompare )
  191.         if( 0 <= dwOffsetToQuoteChar ) then
  192.             strError = Replace( strError, chr(34), "\" & chr(34), 1, Len( strError ), vbTextCompare )
  193.         end if
  194.         
  195.         strError = L_ERRORDESCRIPTION_TEXT & strError
  196.  
  197.         Dim strHexValue
  198.         strHexValue = Hex( Session( "ErrorNumber" ) )
  199.         if( -1 = Session( "ErrorNumber" ) ) then
  200.             strError = Session( "ErrorDescription" )
  201.         else
  202.             strError2 = L_ERRORCODE_TEXT & Server.HTMLEncode( strHexValue )
  203.         end if
  204.  
  205.         %>
  206. <script language="JavaScript">
  207.     window.alert( "<%= strError %>" + "\n" + "<%= strError2 %>" );
  208. </script>
  209. <%
  210.     end if
  211. End Sub
  212.  
  213.  
  214. '/////////////////////////////////////////////////////////////////////////////////////
  215. '
  216. ' If an error is detected, insert javascript to take the user to the previously visited 
  217. '  page, taking care to wipe the current page out of the browser's history buffer
  218. '
  219. sub OnErrorGoBack()
  220.     if 0 <> Session( "ErrorNumber" ) then
  221.         Response.Write( chr(13) & "<script language=JavaScript>" & chr(13) & "window.history.back();" & chr(13) & "</script>" )
  222.     end if
  223. End Sub
  224.  
  225.  
  226. '/////////////////////////////////////////////////////////////////////////////////////
  227. '
  228. ' If an error was saved and we're printing the culprit, display it in error formatted
  229. '   text.  Otherwise, just print the text string.
  230. '
  231. sub RenderWithErrorCheck( ByRef strTextToPrint, ByRef strCulprit )
  232.     if 0 = Session( "ErrorNumber" ) then
  233.         Response.Write strTextToPrint
  234.     elseif ( 0 <> StrComp( strCulprit, Session( "ErrorCulprit" ), vbTextCompare ) ) then
  235.         Response.Write strTextToPrint
  236.     else
  237.         Response.Write "<b><font color=" & chr(34) & "red" & chr(34) & ">"
  238.         Response.Write strTextToPrint
  239.         Response.Write "</b></font>"
  240.     end if
  241. End Sub
  242.  
  243. '/////////////////////////////////////////////////////////////////////////////////////
  244. '                           PRIVATE    SUBROUTINES 
  245. '/////////////////////////////////////////////////////////////////////////////////////
  246.  
  247.  
  248. '/////////////////////////////////////////////////////////////////////////////////////
  249. '
  250. ' Clear the error information.  Should ONLY be called by ErrorCleanUp.
  251. '
  252. Sub ClearError()
  253.     Session( "ErrorNumber" ) = 0
  254.     Session( "ErrorDescription" ) = ""
  255.     Session( "ErrorCulprit" ) = ""
  256.     Err.Clear
  257.     Session( "PageReloadedToDisplayError" ) = 0
  258. End Sub
  259. %>
  260.